package cn.cjxy.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 请求参数相关方法
 *  *  String getParameter(String name)	通过参数的名字得到参数值
 *  *  String[] getParameterValues(String name)	得到所有同名的参数值，一般用复选框。 返回一个字符串数组
 *  *  Enumeration<String> getParameterNames()	得到所有的参数名字，返回枚举类型
 *  *  Map<String,String[]> getParameterMap()	得到所有参数名和值，封装成Map对象 键就是参数名字，值就是参数的值
 *
 *
 * @date 2025/9/26
 */
@WebServlet("/reqParam")
public class RequestParamMethods  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码格式-----网页输出乱码
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String gender = req.getParameter("gender");
        String city = req.getParameter("city");
        String[] hobbies = req.getParameterValues("hobby");

        System.out.println(name+gender+city);
        for (String hobby : hobbies) {
            System.out.println(hobby);
        }

    }
}
